<?php
namespace Tbf\Component\Crypto;
class CryptoRandUtil extends Random
{
    public static function binary($len)
    {
        if (function_exists('openssl_random_pseudo_bytes')) {
            //先找openssl
            $r = openssl_random_pseudo_bytes($len,$tmp);
            if ($r!==FALSE) {
                return $r;
            }
        }
        if (file_exists('/dev/urandom')) {
            //再去找系统
            $r =  fread(fopen('/dev/urandom', 'r'),$len);
            if (!empty($r)) {
                return $r;
            }
        }
        throw new \Exception('not crypto function');
    }//function binary
}//class
